import {
  throttle,
  cloneDeep
} from 'miniprogram-licia'
// 封装了 444 个模块  类似于 jquery lodash 综合整合的库
Page({
  goPassport(ev) {
    wx.navigateTo({
      url: '/visitor_pkg/pages/passport/index?id=' + ev.mark.id,
    })
  },
  data: {
    queryParam: {
      current: 1,
      pageSize: 5
    },
    pageTotal: 0,
    list: []
  },
  onShow() {
    this.getList()
    const obj = [{
      a: 1
    }, {
      a: 2
    }];
    const obj2 = cloneDeep(obj);
    console.log(obj[0] === obj2[1]); // -> false
  },
  // 获取访客记录
  async getList() {
    const res = await wx.http.get('/visitor', this.data.queryParam)
    this.data.list.push(...res.data.rows) // 先追加 再赋值
    this.setData({
      list: this.data.list,
      pageTotal: res.data.pageTotal // 总页数
    })
  },
  // 滚动触底加载下一页数据
  scrolltolower() {
    if (this.data.queryParam.current >= this.data.pageTotal) return wx.utils.toast('没有更多了')
    // 让页码加1
    const fn = throttle(() => {
      this.setData({
        'queryParam.current': this.data.queryParam.current + 1
      })
      this.getList()
    })
    fn()
  },

})